package com.jdew.thkj.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.jdew.thkj.R;
import com.wang.avi.AVLoadingIndicatorView;

public class LoadingDialog extends AlertDialog {

    private static LoadingDialog loadingDialog;
    public static AVLoadingIndicatorView avi;

    public static synchronized LoadingDialog getInstance(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.loading_item, null);// 得到加载view
        avi = (AVLoadingIndicatorView)v.findViewById(R.id.avi);
        loadingDialog = new LoadingDialog(context.getApplicationContext(),R.style.TransparentDialog); //设置AlertDialog背景透明
        loadingDialog.setCancelable(true);
        loadingDialog.setCanceledOnTouchOutside(true);
        return loadingDialog;
    }

    public LoadingDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    public void show() {
        super.show();
        if (null != avi) {
            avi.show();
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (null != avi) {
            avi.hide();
        }
    }
}
